Skip to content

feat: astro logger#13787

Open
ematipico wants to merge 4 commits intomainfrom
feat/astro-logger
Open

feat: astro logger#13787
ematipico wants to merge 4 commits intomainfrom
feat/astro-logger

Conversation

@ematipico
Copy link
Copy Markdown
Member

@ematipico ematipico commented Apr 22, 2026

Description (required)

This PR adds documentation for the upcoming experimental logger. The RFC is here: withastro/roadmap#1339

Linear: AST-84

For Astro version: 6.2.0. See astro PR #16437.

The attached PR is the one that mostly documents the new APIs

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 22, 2026

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit 4a21df6
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/69eb78fa0524920008052fb9
😎 Deploy Preview https://deploy-preview-13787--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@astrobot-houston
Copy link
Copy Markdown
Contributor

astrobot-houston commented Apr 22, 2026

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/reference/experimental-flags/logger.mdx Localization added, will be marked as complete.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

Copy link
Copy Markdown
Member

@ArmandPhilippot ArmandPhilippot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Ema! I left a few suggestions mostly around:

  • docs style, consistency with other experimental pages
  • and some reorganization to make it easier to scan. For example I find the API block placement a bit annoying currently:
API block between the introductory sentence and the list

Also, I noticed you mentioned the AstroLoggerDestination but I don't think we document its exact shape at the moment. It would be helpful to have a "Types reference" section with the public types/types required to build a custom logger.

Then, when the feature becomes stable we only need to reorganize the contents, everything would already be here.

For example, the experimental Route caching has an API reference but we could also use the same format used in the other references (e.g. Renderer types).

Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/logger.mdx Outdated
@ArmandPhilippot ArmandPhilippot added add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) minor-release For the next minor release; in the milestone, "merge queue" = approved for merging on release day. labels Apr 22, 2026
@ArmandPhilippot ArmandPhilippot added this to the 6.2 milestone Apr 22, 2026
@ematipico
Copy link
Copy Markdown
Member Author

Also, I noticed you mentioned the AstroLoggerDestination but I don't think we document its exact shape at the moment. It would be helpful to have a "Types reference" section with the public types/types required to build a custom logger.

I was hoping to get some suggestions on where to have it, and if it needs an header

@ArmandPhilippot
Copy link
Copy Markdown
Member

If there is only one useful type, a reference section might not be the best approach and we could reshape Custom loggers with something similar to session drivers:

A type reference section

(we don't necessarily need to show write(), etc. in the sidebar, this was just to show the hierarchy)

Otherwise, a new section at the end might be easier to organize the content. Each section only describe what is available and we add links to the relevant types for advanced users. This remains easy to scan without having to scroll too much for those not interested in building their own logger. Something like:

A building a custom logger section

And we have precedents for both approaches, so the structure remains familiar to users.

ematipico and others added 3 commits April 24, 2026 13:43
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
@ematipico
Copy link
Copy Markdown
Member Author

Hey @ArmandPhilippot , I added more information to the page. Let me know what you think

Copy link
Copy Markdown
Member

@ArmandPhilippot ArmandPhilippot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, @ematipico !

I left a few suggestions, most of them try to shorten/simplify the wording or add links when we can. And one of them is pretty big: if we replace your list with sections, we can link to them directly when needed and this might be easier to scan.

Feel free to disagree. 😄 After that, it looks ready to me!


### `logHandlers.compose`

A particular function that allows using multiple loggers. The same message is broadcasted to all loggers. The function accepts an arbitrary number of logger configurations.logHandlers
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your autocomplete function is playing tricks on us again (.logHandlers) 😄 But I think we can combine the first and last sentence:

Suggested change
A particular function that allows using multiple loggers. The same message is broadcasted to all loggers. The function accepts an arbitrary number of logger configurations.logHandlers
A particular function that allows configuring multiple loggers in an arbitrary order. The same message is broadcasted to all loggers.

});
```

The following example implements a minimal logger returning an `AstroLoggerDestination` object with the required `write()` function:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now have a link I think this could be helpful here:

Suggested change
The following example implements a minimal logger returning an `AstroLoggerDestination` object with the required `write()` function:
The following example implements a minimal logger returning an [`AstroLoggerDestination` object](#astrologgerdestination) with the required `write()` function:

});
```

We will expose an utility form the `astro/logger` package to check the log level.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the changeset, this is already available, and we avoid "we" 😄

Suggested change
We will expose an utility form the `astro/logger` package to check the log level.
The `astro/logger` package exposes a [`matchesLevel()`](#matcheslevel) helper to check the log level. This can be useful when [building a custom logger](#custom-loggers).

Comment on lines +258 to +261
This is the interface that custom loggers must implement. The following can be implemented:
- `write(message: AstroLoggerMessage) => void`: a mandatory method that accepts a `AstroLoggerMessage`. It's called for every log.
- `flush() => Promise<void> | void`: an optional function that is called at end of each request. Useful for advanced loggers for flushing logger messages while keeping the connection to the destination alive.
- `close() => Promise<void> | void`: an optional function that is called before a server is shut down. This is a function usually called by adapters such as `@astrojs/node`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing really wrong but:

  • with sections, this is easier to scan and this allows us to use links to these sections.
  • I simplified a bit some sentences (e.g. function that is called > function called) to make them look like definitions
Suggested change
This is the interface that custom loggers must implement. The following can be implemented:
- `write(message: AstroLoggerMessage) => void`: a mandatory method that accepts a `AstroLoggerMessage`. It's called for every log.
- `flush() => Promise<void> | void`: an optional function that is called at end of each request. Useful for advanced loggers for flushing logger messages while keeping the connection to the destination alive.
- `close() => Promise<void> | void`: an optional function that is called before a server is shut down. This is a function usually called by adapters such as `@astrojs/node`.
This is the interface that custom loggers must implement.
#### `AstroLoggerDestination.write()`
<p>
**Type:** `(message: AstroLoggerMessage) => void`
</p>
A mandatory method called for each log and accepting an [`AstroLoggerMessage`](#astrologgermessage).
#### `AstroLoggerDestination.flush()`
<p>
**Type:** `() => Promise<void> | void`
</p>
An optional function called at the end of each request. This is useful for advanced loggers that need to flush log messages while keeping the connection to the destination alive.
#### `AstroLoggerDestination.close()`
<p>
**Type:** `() => Promise<void> | void`
</p>
An optional function called before a server is shut down. This function is usually called by adapters such as `@astrojs/node`.

For the last sentence I hesitated to simplify it:

-An optional function called before a server is shut down. This function is usually called by adapters such as `@astrojs/node`.
+An optional function called by adapters (e.g. `@astrojs/node`) before shutting down the server.

But maybe "usually" was intentional so I haven't updated that.


### `AstroLoggerMessage`

The incoming object from the `AstroLoggerDestination.write` function:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the previous suggestion, we can now add a link here:

Suggested change
The incoming object from the `AstroLoggerDestination.write` function:
The incoming object from the [`AstroLoggerDestination.write()`](#astrologgerdestinationwrite) function:

Comment on lines +272 to +273
### `AstroLoggerMessage`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is inlining the type useful here? I mean I noticed you specified that message is a string below and I see that label can be null

Suggested change
### `AstroLoggerMessage`
### `AstroLoggerMessage`
<p>
**Type:** `{ label: string | null; level: AstroLoggerLevel; message: string; newLine: boolean; }`
</p>

### `AstroLoggerMessage`

The incoming object from the `AstroLoggerDestination.write` function:
- `message: string`: the message being logged.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If my previous suggestion makes sense we no longer need this and all items are consistent:

Suggested change
- `message: string`: the message being logged.
- `message`: the message being logged.


### `matchesLevel`

`matchesLevel(messageLevel: AstroLoggerLevel, configuredLevel: AstroLoggerLevel): boolean`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, formatting:

Suggested change
`matchesLevel(messageLevel: AstroLoggerLevel, configuredLevel: AstroLoggerLevel): boolean`
<p>
**Type:** `matchesLevel(messageLevel: AstroLoggerLevel, configuredLevel: AstroLoggerLevel) => boolean`
</p>


`matchesLevel(messageLevel: AstroLoggerLevel, configuredLevel: AstroLoggerLevel): boolean`

Given two [logger level](#log-level), it returns whether the first level matches the second level.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Given two [logger level](#log-level), it returns whether the first level matches the second level.
Given two [log levels](#log-level), it returns whether the first level matches the second level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) minor-release For the next minor release; in the milestone, "merge queue" = approved for merging on release day.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants